<template>
  <div class="main">
    <!-- <img :src="'https://www.icottontrade.com/cot/Upload/pic/' + url + '?t='+new Date()" alt=""> -->
    <img :src="'https://www.icottontrade.com/cot/Upload/pic/' + url + '?t='+new Date()" alt>
  </div>
</template>

<script>
export default {
  data() {
    return {
      url: "",
      timer: null
    };
  },
  created() {
    var that = this;
    this.url = this.$route.query.url;
    var num = 10;
    
    this.timer = setInterval(() => {
      if (num <= 0) {
        clearInterval(this.timer);
        console.log("error");
      }
      if (that.$store.state.userInfo && that.$store.state.userInfo.NickName && iswx) {
        that.share();
        //document.title = "批次图片查看";
        clearInterval(this.timer);
        console.log("success");
      } else {
        num--;
      }
    }, 500);
  },
  methods: {
    share() {
      var link = "";
      var url =
        "https://www.icottontrade.com/cot/redirect/SharePic?url=" +
        encodeURI(this.$route.query.url);
      console.log(url);
      var entLogo =
        "https://www.icottontrade.com/cot/upload/mylogo/" +
        this.$store.state.userInfo.logo;
      console.log(entLogo);
      var logoUrl = this.$store.state.userInfo.logo
        ? entLogo
        : "https://www.icottontrade.com/cot/upload/logo.jpg";
      wx.onMenuShareAppMessage({
        title: this.$store.state.userInfo.NickName + "为您推荐",
        desc: "聚棉网为您推荐以下资源",
        link: url, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
        imgUrl: logoUrl, // 自定义图标
        type: "link", // 分享类型,music、video或link，不填默认为link
        dataUrl: "", // 如果type是music或video，则要提供数据链接，默认为空
        success: function() {
          // 用户确认分享后执行的回调函数
          Toast({
            message: "分享成功",
            duration: 1500
          });
        },
        cancel: function() {
          // 用户取消分享后执行的回调函数
        }
      });
      wx.onMenuShareTimeline({
        title: this.$store.state.userInfo.EntName,
        link: url,
        imgUrl: logoUrl // 自定义图标
      });
    }
  }
};
</script>

<style scoped lang='less'>
.main {
  img {
    width: 100%;
    display: block;
  }
}
</style>